<?php
class ManagerModel extends MY_Model {
	
	function ManagerModel() {
		parent::MY_Model ('manager');
	}
	
	/**
	 * 按照session里的user_id 和 工作人员类型得到管理人员
	 * @param $user_id
	 */
	function get_manager($user_id, $m_category) {
		$sql = "select * from manager where user_id = ? and m_category = ?";
		$query =  $this->db->query($sql, array($user_id, $m_category));
		$data = $query->row_array();
		return $data;
	}
	
	/**
	 * 按照session里的user_id得到管理人员
	 * @param $user_id
	 */
	function get_managers($user_id) {
		$sql = "select * from manager where user_id = ? order by m_category";
		$query =  $this->db->query($sql, array($user_id));
		$data = $query->result();
		return $data;
	}
	
	/**
	 * 保存
	 * @param unknown_type $data
	 */
	function save_manager($data) {
		$db_data = $this->get_manager($data['user_id'], $data['m_category']);
		if ($db_data) {
			$this->db->where("user_id", $data['user_id']);
			$this->db->where("m_category", $data['m_category']);
			$this->db->update("manager", $data);
		} else {
			$this->insert($data);
		}
	}
	
}